package com.ezops.dtcc.model.dao;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.jdbc.core.JdbcTemplate;

import com.ezops.dtcc.model.DtccRulesSql;
import com.ezops.dtcc.rowmapper.DtccRulesSqlRowMapper;


public class DtccRulesSqlDAO {
	private final static Logger LOGGER = Logger
			.getLogger(DtccRulesSqlDAO.class);
	private JdbcTemplate jdbcTemplate;

	public DtccRulesSqlDAO(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}

	public JdbcTemplate getJdbcTemplate() {
		return jdbcTemplate;
	}

	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}
	
	public void insert(DtccRulesSql rulesSql) {
		
		
	}
	
	public List<DtccRulesSql> findAll() {
		
		
		String selectHuginUser = "SELECT * DTCC_RULE_SQL";
		List<Object> resultList = this.jdbcTemplate.query(selectHuginUser,  new DtccRulesSqlRowMapper());
		List<DtccRulesSql> ruleSqlList = new ArrayList<DtccRulesSql>();
		if (resultList != null && !resultList.isEmpty()) {
		    for (int i = 0; i < resultList.size(); i++) {
		    	ruleSqlList.add((DtccRulesSql) resultList.get(i));		
		    }
		}	
		return ruleSqlList;
		
		
	}
	
	public DtccRulesSql findById(int ruleId) {

		DtccRulesSql foundItem = null;
		String selectRuleSql = "SELECT * DTCC_RULE_SQL WHERE RULE_ID = " + ruleId;
		List<Object> resultList = this.jdbcTemplate.query(selectRuleSql,  new DtccRulesSqlRowMapper());
		if(!resultList.isEmpty() ) 
			foundItem = (DtccRulesSql)resultList.get(0);
		
		
		return foundItem;
		
		
	}
	
	
}
